package com.stxx.stiot2.service.impl;

import com.stxx.framwork.domain.model.PageQuery;
import com.stxx.framwork.domain.model.PageResult;
import com.stxx.framwork.utils.StoreUtils;
import com.stxx.stiot2.domain.Driver;
import com.stxx.stiot2.service.DriverService;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;

import java.sql.SQLException;
import java.util.List;

/**
 * @author Fuzhenlei
 * @date 2025/01/15 16:41
 */
@Component
public class DriverServiceImpl implements DriverService{
    @Inject
    StoreUtils storeUtils;

    @Override
    public Driver queryById(Integer id) {
        try {
            return storeUtils.selectById(id,Driver.class);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public int insert(Driver bean) throws SQLException {
        validEntityBeforeSave(bean);
        return storeUtils.insert(bean);
    }

    @Override
    public int update(Driver bean) throws SQLException {
        validEntityBeforeSave(bean);
        return storeUtils.update(bean);
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(Driver bean){

    }

    @Override
    public int delete(Integer id) throws SQLException {
        return storeUtils.delete(Driver.class, id);
    }

    @Override
    public int deleteByIds(Integer[] ids) throws SQLException {
        return storeUtils.deleteByIds(Driver.class, ids);
    }

    @Override
    public List<Driver> list(Driver obj) throws SQLException {
        return storeUtils.selectList(Driver.class,obj);
    }

    @Override
    public PageResult<Driver> pageList(Driver obj, PageQuery pageQuery) throws SQLException {
        return storeUtils.selectPageList(Driver.class,obj,pageQuery);
    }
}
